extends NodeState


@export var igorBoss: IgorBoss

var velocity: Vector2 = Vector2.ZERO
var death: bool = false


func _on_process(delta : float) -> void:
	igorBoss.position += velocity * delta


func _on_next_transitions() -> void:
	if not death and igorBoss.current_health <= 0:
		death = true
		transition_state(IgorBoss.STATE_DEATH)


func _on_enter() -> void:
	process_animation()
	process_affected()


func _on_exit() -> void:
	pass


func _allow_repeat_enter() -> bool:
	return true


func on_hurt_animation_finished():
	transition_state(IgorBoss.STATE_IDLE)


func process_animation():
	igorBoss.animationPlayer.play(IgorBoss.ANIMATION_HURT)


# 受到攻击时的效果
func process_affected():
	var emit_direction := igorBoss.take_damage_emit_direction()
	if emit_direction == null:
		return
	var direction: Vector2 = Vector2.RIGHT if emit_direction.x > 0 else Vector2.LEFT
	velocity = direction * igorBoss.knockback_intensity
